var app = getApp();
Component({
  options: {
    addGlobalClass: true
  },
  properties: {
    // 这里定义了innerText属性，属性值可以在组件使用时指定
  },
  data: {
    userInfo: '',
    // 这里是一些组件内部数据
    types: ['topLeft', 'topRight', 'bottomLeft', 'bottomRight', 'center'],
    typeIndex: 3,
    colors: [
      'light',
      'stable',
      'positive',
      'calm',
      'balanced',
      'energized',
      'assertive',
      'royal',
      'dark',
    ],
    colorIndex:7,
    dirs: ['horizontal', 'vertical', 'circle'],
    dirIndex: 1,
    sAngle: 0,
    eAngle: 360,
    spaceBetween: 10,
    buttons: [{
      // openType: 'getUserInfo',
      label: '发布信息',
      icon: "",
    },
    //  {
    //   openType: 'getUserInfo',
    //   label: '发布留言',
    //   icon: '',
    // },
    // {
    //   // openType: 'getUserInfo',
    //   label: '问题反馈',
    //   icon: '',
    // },
    {
      // openType: 'getUserInfo',
      label: '外卖领券',
      icon: '',
    }, {
      openType: 'contact',
      label: '在线客服',
      icon: '',
    }
    ],
  },
  onload() {

  },
  methods: {
    onContact(e) {
      console.log('onContact', e)
    },
    // 点击悬浮按钮发布信息需要授权个人信息
    fabbuttonAction(e) {
      console.log(e.detail.value.label)
      let HASUSERINFO = app.HASUSERINFO()
      if ('wait' == HASUSERINFO) {
        return
      }
      console.log(HASUSERINFO)
      // 如果没有授权过，需要用户授权
      if (!HASUSERINFO) {
        app.getUserProfile().then(res => {
          if (res.status) {
            // 判断是否能够发布
            let userBehaviorLimit = wx.getStorageSync('ALLINFO').userBehaviorLimit
            if (userBehaviorLimit.canWeekPunlishTopic) {
              if (userBehaviorLimit.canDayPunlishTopic) {
                wx.navigateTo({
                  url: '/pages/components/issue/issue',
                })
              } else {
                wx.showToast({
                  title: '今天发布次数已达上限！',
                  icon: 'none'
                })
              }
            } else {
              wx.showToast({
                title: '本周发布次数已达上限！',
                icon: 'none'
              })
            }
          }
        })
      } else {
        // 如果已经授权，则直接跳转相应表单
        if (e.detail.value.label == "发布信息") {
          // 判断是否能够发布
          let userBehaviorLimit = wx.getStorageSync('ALLINFO').userBehaviorLimit
          if (userBehaviorLimit.canWeekPunlishTopic) {
            if (userBehaviorLimit.canDayPunlishTopic) {
              wx.navigateTo({
                url: '/pages/components/issue/issue',
              })
            } else {
              wx.showToast({
                title: '今天发布次数已达上限！',
                icon: 'none'
              })
            }
          } else {
            wx.showToast({
              title: '本周发布次数已达上限！',
              icon: 'none'
            })
          }
        }
        //  else if (e.detail.value.label == "发布留言") {
        //   wx.switchTab({
        //     url: '/pages/msg/msg'
        //   })
        // } 
        else if (e.detail.value.label == "问题反馈") {
          wx.navigateTo({
            url: '/pages/components/feedback/feedback',
          })
        }else if(e.detail.value.label == "外卖领券"){
          wx.navigateTo({
            url: '/pages/components/msg/savemoney/savemoney',
          })
        }
      }
    },

    onGotPhoneNumber(e) {
      console.log('onGotPhoneNumber', e)
    },
    onChange(e) {
      // console.log('onChange', e)
    },
    pickerChange(e) {
      const {
        value
      } = e.detail
      const {
        model
      } = e.currentTarget.dataset

      this.setData({
        [model]: value,
      })
    },
    onSwitch(e) {
      this.setData({
        reverse: e.detail.value,
      })
    },
    onAngle(e) {
      const {
        value
      } = e.detail
      const sAngle = value ? -90 : 0
      const eAngle = value ? -210 : 360
      const spaceBetween = value ? 30 : 10

      this.setData({
        sAngle,
        eAngle,
        spaceBetween,
      })
    }
  },
})